<template>
	<view class="login">
		<view class="login-header">
			<view class="hello">你好!</view>
			<view class="welcome">欢迎回来,大家都很想念你</view>
		</view>

		<view class="login-form">
			<view class="username-form">
				<view class="detale-icon" v-if="username!=''" @click="username=''"></view>
				<view class="username-title">账号</view>
				<input type="text" class="username" v-model="username" />
			</view>
			<view class="password-form">
				<view class="password-icon" :class="isShow==true?'active':''" @click="isShow = !isShow"></view>
				<view class="password-titile">密码</view>
				<input :type="isShow?'text':'password'" class="password" v-model="password" />
				<!-- <input type="password" class="password" v-model="password" /> -->
			</view>
			<view class="login-func">
				<view class="func-left">
					<uni-data-checkbox multiple v-model="value" :localdata="range" @change="change"></uni-data-checkbox>
					<!-- <view class="remember">记住我</view> -->
				</view>
				<view class="func-right">
					<view class="forget" @click="goRegister">去注册</view>
				</view>
			</view>
			<view class="submit-butt">
				<view class="submit" @click="userLogin">登录</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from "@/api/request"
	export default {
		data() {
			return {
				username: "15733333333",
				password: "123456",
				isShow: false,
				// accShow:false,
				value: 0,
				range: [{
					'value': 0,
					"text": "记住我"
				}]
			}
		},
		methods: {
			goRegister(){
				uni.navigateTo({
					url:"/pages/register/register"
				})
			},
			//登录
			userLogin() {
				if (this.username == "") {
					uni.showToast({
						title: "请输入账号",
						icon: "none"
					})
					return
				}
				if (this.password == "") {
					uni.showToast({
						title: "请输入密码",
						icon: "none"
					})
					return
				}
				let data = {
					user_acc: this.username,
					user_pwd: this.password
				};
				login(data).then(content => {
					console.log(content);
					let {
						code,
						userInfo
					} = content
					console.log(userInfo);
					if (code == 200) {
						localStorage.setItem("user_id", userInfo.user_id)
						localStorage.setItem("user_nick_name", userInfo.user_nick_name)
						localStorage.setItem("user_avators", userInfo.user_avators)
						localStorage.setItem("user_message", userInfo.user_message)
						localStorage.setItem("userInfo", JSON.stringify(userInfo))
						uni.showToast({
							title: "登录成功",
							icon: "none",
						})
						uni.switchTab({
							url: "../../pages/index/index"
						})
					}
				}).catch(err => {
					console.log(err);
				})
			},
			change(e) {
				console.log('e:', e);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login {
		width: 100%;
		padding: $uni-box-padding;
	}

	.login-header {
		padding-bottom: 60rpx;

		.hello {
			font-size: 96rpx;
			color: #000;
			font-weight: bold;
		}

		.welcome {
			padding-top: 30rpx;
			font-size: 40rpx;
			color: #4E4B66;
		}
	}

	.login-form {
		width: 100%;
		padding: 30rpx 0;


		.password-form,
		.username-form {
			padding-bottom: 40rpx;

			.password-titile,
			.username-title {
				font-size: 32rpx;
				color: #4E4B66;
				padding-bottom: 10rpx;
			}

			.password,
			.username {
				width: 100%;
				border: 1px solid #4E4B66;
				padding: 0 20rpx;
				height: 76rpx;
				line-height: 76rpx;
				border-radius: 10rpx;
				box-sizing: border-box;
				outline: 0;
			}
		}

		.username-form {
			position: relative;

			.detale-icon {
				z-index: 1;
				position: absolute;
				top: 70rpx;
				right: 10rpx;
				width: 48rpx;
				height: 48rpx;
				background-image: url("@/static/image/detele.png");
				background-repeat: no-repeat;
				background-size: 100%;
			}
		}

		.password-form {
			position: relative;
			padding-bottom: 10rpx;

			.password-icon {
				z-index: 1;
				position: absolute;
				top: 70rpx;
				right: 10rpx;
				width: 48rpx;
				height: 48rpx;
				background-image: url("@/static/image/notlook.png");
				background-repeat: no-repeat;
				background-size: 100%;

				&.active {
					background-image: url("@/static/image/look.png");
				}
			}
		}

		.login-func {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.forget {
				font-size: 28rpx;
				color: #5890FF;
			}
		}

		.submit-butt {
			padding-top: 30rpx;
			text-align: center;

			.submit {
				padding: 15rpx 0;
				margin: 0 auto;
				// width: 70%;
				background-color: #5890FF;
				border-radius: 10rpx;
				color: #fff;
			}
		}
	}
</style>